﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GzipManagerPro.IO
{
    
    partial class Folder
    {

        public override bool ExtractTo(string path, Archive archive)
        {
            return ExtractTo(path, archive, null);
        }

        public override bool ExtractTo(string path, Archive archive, string password)
        {
            
            path = string.IsNullOrEmpty(this.Name ) ? path : System.IO.Path.Combine(path, this.Name);

            archive.CheckPassword(password);

            System.IO.Directory.CreateDirectory(path);
            archive.OnArchiveMessage(new ArchiveMessageEventArgs(archive.TotalProgress, archive.CurrentProgress, "extracting folder {0}...", this.Name));
            this.Files.ForEach(f =>
            {
                archive.OnArchiveMessage(new ArchiveMessageEventArgs(archive.TotalProgress, archive.CurrentProgress, "extracting file {0}...", f.Name));
                f.ExtractTo(path, archive, password);
                archive.CurrentProgress++;
            });
            this.Folders.ForEach(f => f.ExtractTo(path, archive, password));
            return true;
        }

    }
}
